/*
 * CPrcessFactory.cpp
 *
 *  Created on: 2012-3-30
 *      Author: li.zhaoping
 */

#include "CPrcessFactory.h"
#include <dlfcn.h>     //用于动态库管理的系统头文件

#include "../utility/easyLog.h"

#include "CTbx_Process.h"
#include "CVoc_Process.h"


CProcess* CPrcessFactory::CreateProcess(std::string strUrl,std::string strRule){
	if (strRule == ""){
		return NULL;
	}
	else if(strRule.find("ruler_tbx") == 0) {
		return new CTbx_Process();
	}
	else if(strRule.find("ruler_voc") == 0) {
		return new CVoc_Process();
	}
	else{
		std::string libs = "./" + strRule ;
		libs += ".so";
		void* pdlHandle = dlopen(libs.c_str(), RTLD_LAZY);
		 if(pdlHandle == NULL){
			 ERR_("load lib[%s] fail!\n",libs.c_str());
			 return NULL;
		 }
		 char* pszErr = dlerror();
		 if(pszErr != NULL)
		{
			 ERR_("dlerror0 [%s]\n", pszErr);
			 return NULL;
		}
		 void(*pTest)();
		 pTest = (void(*)())dlsym(pdlHandle, "test");
		 if(pszErr != NULL)
		{
			 ERR_("dlerror1 [%s]\n", pszErr);
			 return NULL;
		}
		 (*pTest)();
		 dlclose(pdlHandle);
		 return NULL;
	}

	return NULL;
}
